<template>
  <div style>
    <el-row :gutter="0">
      <!--            大屏幕-->
      <el-col
        :xs="24"
        :sm="24"
        :md="16"
        :lg="12"
        :xl="12"
        class="center_vertically hidden-sm-and-down"
      >
        <div style="display: flex; margin-left: 10%" class="shadow">
          <div style="flex: 1">
            <img :src="imgList[0]" style="width: 100%;
                            display: block;" />
            <img
              :src="imgList[1]"
              style="width: 100%;height:auto;margin-top: 0;
                            display: block;"
            />
          </div>
          <div style="flex: 1;">
            <img :src="imgList[2]" style="width: 100%;
                            display: block;" />
            <img :src="imgList[3]" style="width: 100%;display: block" />
          </div>
        </div>
        <div style="position:absolute;right: 50%;top: 65%; z-index: 999;background-color: #e7e7e7">
          <h3 class="landing_page_subtitle" align="right">{{text}}</h3>
          <p align="right">--匿名</p>
        </div>
      </el-col>
      <el-col
        :xs="24"
        :sm="24"
        :md="8"
        :lg="12"
        :xl="12"
        style
        align="middle"
        class="center_vertically hidden-sm-and-down"
      >
        <div
          style="
              height: 30em;
              width:50%;
              min-width: 350px;
              background: rgb(255,255,255);"
          class="login_info"
        >
          <h2 style="font-size: 40px;">管理系统</h2>
          <div class="input">
            <el-input placeholder="请输入账号" v-model="login" />
          </div>
          <div class="input">
            <el-input placeholder="请输入密码" v-model="psd" />
          </div>
          <div class="input">
            <el-button type="primary" style="width: 100%" @click="btn_login">登录</el-button>
          </div>
          <div style="width: 80%; margin-top: 13em">
            <el-divider style="background-color: #999999">酸牛来</el-divider>
          </div>
        </div>
      </el-col>

      <!--小屏幕-->
      <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12" class="hidden-md-and-up">
        <div
          class="small_text_on_login_page"
          style="align-items:start;text-align: right"
          align="right"
        >
          <div style="width: 50%; background-color: #e7e7e7">
            <h3 class="landing_page_subtitle">{{text}}</h3>
            <p>--匿名</p>
          </div>
        </div>
      </el-col>

      <el-col
        :xs="24"
        :sm="24"
        :md="8"
        :lg="12"
        :xl="12"
        style="margin: 0;padding: 0"
        align="middle"
        class="hidden-md-and-up"
      >
        <div
          style="
                margin-left: 0;
                float: left;
              width:100%;
              background: rgb(255,255,255);"
          class="login_info"
        >
          <div class="input" style="margin-top: 5em">
            <el-input placeholder="请输入账号" v-model="login" />
          </div>
          <div class="input">
            <el-input placeholder="请输入密码" v-model="psd" />
          </div>
          <div class="input">
            <el-button type="primary" style="width: 100%" @click="btn_login">登录</el-button>
          </div>
          <div style="width: 80%; margin-top: 35%">
            <el-divider style="background-color: #999999">酸牛来</el-divider>
          </div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
let that;
export default {
  name: "Login",
  data() {
    return {
      text: "",
      imageURL: "",
      imgList: [],
      login: "",
      psd: ""
    };
  },
  methods: {
    btn_login() {
      if (that.login.trim() === "" || that.psd.trim() === "") {
        alert("你好像没输入什么东西");
      } else {
        const timestamp = new Date().getTime().toString();
        const json = {
          login: that.login,
          psd: that.psd,
          timestamp: timestamp
        };
        let doSign = that.doSign(json);
        that.Axios.post(that.USER_API + "/login/" + doSign, json).then(function(
          result
        ) {
          let statusCode = result.data.status_code;
          if (statusCode === 1) {
            alert("欢迎回来");
            let token = result.data.result.token;
            that.$store.commit("login", token);
            that.$router.push({
              path: "/index"
            });
          } else {
            alert("账号或密码错误");
            that.login = "";
            that.psd = "";
          }
        });
      }
    }
  },
  mounted() {
    that = this;
    document.title = "登录";
    let axiosInstance = that.Axios.create({
      headers: {
        // 'Content-Type': 'application/json;charset=utf-8',
        // 'Access-Control-Allow-Origin':'*'
      }
      // withCredentials: true,// 指定某个请求应该发送凭据。允许客户端携带跨域cookie，也需要此配置
    });
    axiosInstance.get(that.WORDOFTHEDAY_API).then(function(res) {
      that.text = res.data.text;
    });

    axiosInstance.post(that.TOOL_API + "/bing/4").then(function(result) {
      let data = result.data.data;
      data.forEach(o => {
        that.imgList.push(o.url);
      });
    });
  }
};
</script>


<style scoped src="element-ui/lib/theme-chalk/display.css"/>
<style scoped>
.login_info :hover {
  /*transform: translateX(100px);*/
}

.el-divider {
  background-color: #c5c5c5;
  position: relative;
}

.input {
  width: 80%;
  margin-top: 6%;
}

.center_vertically {
  height: 100%;
  margin-top: 10%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.small_text_on_login_page {
  background-image: url("https://api.xygeng.cn/bing/1366.php");
  background-size: 100%;
  height: 20%;
  width: 100%;
  text-align: right;
  padding-top: 10%;
  padding-bottom: 10%;
}

.large_text_on_login_page {
  background-image: url("https://api.xygeng.cn/bing/1366.php");
  background-size: 100%;
  height: 25em;
  width: 80%;
  margin-left: 10%;
  padding: 5%;
}

.landing_page_subtitle {
  font-size: 1em;
  font-family: Georgia, Palatino, serif;
}
</style>